import 'package:common_utils/common_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBJsonToModel/YBMineModel/YBMineGongDanModel.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBJsonToModel/YBMineModel/YBMyGongDanDetailModel.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBNetWorkModule/YBBaseMineNetWork/YBBaseMineNetWork.dart';

class YBBaseMineProvider with ChangeNotifier {

  List<YBMineGongDanModel> _gongDanModel = List<YBMineGongDanModel>();

  List<YBMineGongDanModel> get gongDanModelList => _gongDanModel;

  RefreshController _easyRefreshController = RefreshController();

  RefreshController get easyRefresh => _easyRefreshController;

  int _currentPage = 1;

  void refreshData(String isTakeOrder,String requestTypes){
    _currentPage = 1;
    getGongDanInfoData(_currentPage, isTakeOrder, requestTypes);
  }

  void loadData(String isTakeOrder,String requestTypes){
    _currentPage++;
    getGongDanInfoData(_currentPage, isTakeOrder, requestTypes);
  }

  void getGongDanInfoData(int page,String isTakeOrder,String requestTypes){
    YBMineNetWork.mineGongDanInfoData({
      "pageSize":20,
      "pageNo":page,
      "isTakeOrder":isTakeOrder,
      "requestTypes":requestTypes
    },success: (data){
      _easyRefreshController.refreshCompleted();
      _easyRefreshController.loadComplete();
      print('--object---$data');

      if(page == 1){
        _gongDanModel.clear();
      }

      int totalPage = data['totalPage'];
      if (totalPage == page) {
        _easyRefreshController.loadNoData();
      }
      List resultList = data['result'];
      if (!ObjectUtil.isEmptyList(resultList)) {
        _gongDanModel.addAll(resultList.map((e){
          return YBMineGongDanModel.fromJson(e);
        }).toList());
        notifyListeners();
      }

    },fail: (error){
      print('--error---$error');
    });
  }

}

class YBMineMyGongDanDetailProvider with ChangeNotifier{

  YBMyGongDanDetailModel gongDanDetailModel;

  void getShangJiKuData(String sysCode,String requestCode){
    YBMineNetWork.mineMyGongDanXiangQingData({
      "sysCode":sysCode,
      "requestCode":requestCode,
    },success:(data){
      print('--工单信息---$data--');
      gongDanDetailModel = YBMyGongDanDetailModel.fromJson(data);
      notifyListeners();
    },fail: (error){
      print('--$error-');
    });
  }
}
